package com.bm.beautifulmouse;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Screen;
import javafx.stage.Stage;
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * 应用程序主入口类
 */
public class MainApplication extends Application {
    
    @Override
    public void start(Stage stage) throws Exception {
        // 初始化全局鼠标监听
        initializeGlobalMouseHook();
        
        // 加载主界面
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
        Scene scene = new Scene(fxmlLoader.load());
        
        // 添加样式表
        scene.getStylesheets().addAll(
            getClass().getResource("/css/style.css").toExternalForm(),
            getClass().getResource("/css/effect-style.css").toExternalForm()
        );
        
        // 获取屏幕尺寸
        Screen screen = Screen.getPrimary();
        double screenWidth = screen.getBounds().getWidth();
        double screenHeight = screen.getBounds().getHeight();
        
        // 配置舞台
        stage.setTitle("Beautiful Mouse");
        stage.setScene(scene);
        stage.setMaximized(true); // 设置最大化
        stage.setMinWidth(800);   // 设置最小宽度
        stage.setMinHeight(600);  // 设置最小高度
        
        // 显示舞台
        stage.show();
    }

    private void initializeGlobalMouseHook() {
        Logger.getLogger(GlobalScreen.class.getPackage().getName()).setLevel(Level.OFF);
        try {
            GlobalScreen.registerNativeHook();
        } catch (NativeHookException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}